package com.tanhua.server.controller;

import com.tanhua.model.domain.BaseResult;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/users")
public class UsersController {

    @Autowired
    private UserInfoService userInfoService;

    @GetMapping
    public ResponseEntity users(@RequestHeader("Authorization") String token,
                                Long userId){

        if(userId == null){
            userId = UserHolder.getUserId();
        }
        UserInfo userInfo = userInfoService.getUserById(userId);
        return ResponseEntity.ok(BaseResult.builder().data(userInfo).build());
    }

}
